<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    从流开始的IO世界生活(四) |  Yolin
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.png" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="Yolin" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-从流开始的IO世界生活-四" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  从流开始的IO世界生活(四)
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/08/12/%E4%BB%8E%E6%B5%81%E5%BC%80%E5%A7%8B%E7%9A%84IO%E4%B8%96%E7%95%8C%E7%94%9F%E6%B4%BB-%E5%9B%9B/" class="article-date">
  <time datetime="2020-08-12T05:58:02.000Z" itemprop="datePublished">2020-08-12</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.6k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="一、标准输入输出流"><a href="#一、标准输入输出流" class="headerlink" title="一、标准输入输出流"></a>一、标准输入输出流</h2><p>System类中有两个静态成员变量</p>
<ul>
<li><strong>public static final InputStream in</strong>：标准输入流。通常该流对应于键盘输入或由主机环境或用户指定的另一个输入源</li>
<li><strong>public static final PrintStream out</strong>:标准输出流。通常该流对应于显示输出或由主机环境或用户指定的另一个输出目标<h3 id="标准输入流"><a href="#标准输入流" class="headerlink" title="标准输入流"></a>标准输入流</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> special;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.BufferedInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.BufferedReader;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStreamReader;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">demo1</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">		<span class="comment">//输入中文会乱码，所以要用字符输入流</span></span><br><span class="line">		InputStream is=System.in;</span><br><span class="line">		<span class="comment">//用转换流将字节流转换为字符流</span></span><br><span class="line">		InputStreamReader isr=<span class="keyword">new</span> InputStreamReader(is);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//用字符缓冲输入流特有方法来实现读取一行</span></span><br><span class="line">		BufferedInputStream bis=<span class="keyword">new</span> BufferedInputStream(is);</span><br><span class="line">		BufferedReader br=<span class="keyword">new</span> BufferedReader(isr);</span><br><span class="line">		System.out.println(<span class="string">"请输入一个字符串"</span>);</span><br><span class="line">		String line=br.readLine();</span><br><span class="line">		System.out.println(line);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<a id="more"></a>
等价于</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">	BufferedReader br=<span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(System.in));</span><br><span class="line">	String line=br.readLine();</span><br><span class="line">	System.out.println(line);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>自己实现键盘录入数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">BufferedReader br=<span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(System.in));</span><br></pre></td></tr></table></figure>
</li>
<li><p>而java提供了一个类实现键盘输入</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Scanner sc=<span class="keyword">new</span> Scanner(System.in);</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="标准输出流"><a href="#标准输出流" class="headerlink" title="标准输出流"></a>标准输出流</h3><p><strong>输出语句的本质是一个标准的输出流</strong></p>
<ul>
<li>PrintStream ps=System.out;</li>
<li>PrintStream类有的方法，System.out都可以使用</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_20-20-33.jpg" alt=""></p>
<h2 id="二、打印流"><a href="#二、打印流" class="headerlink" title="二、打印流"></a>二、打印流</h2><p>打印流分类：</p>
<ul>
<li>字节打印流：PrintStream</li>
<li>字符打印流：PrintWriter</li>
</ul>
<p>打印流的特点：</p>
<ul>
<li>只负责输出数据，不负责读取数据</li>
<li>有自己的特有方法</li>
</ul>
<h3 id="字节打印流"><a href="#字节打印流" class="headerlink" title="字节打印流"></a>字节打印流</h3><ul>
<li>PrintStream(String fileName):使用指定的文件名创建新的打印流</li>
<li>使用继承父类的方法写数据，查看的时候会转码；使用自己的特有方法写数据，查看的数据原样输出</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_20-28-10.jpg" alt=""></p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_20-41-47.jpg" alt=""></p>
<h3 id="字符打印流"><a href="#字符打印流" class="headerlink" title="字符打印流"></a>字符打印流</h3><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_21-37-37.jpg" alt=""></p>
<p>常用构造方法</p>
<table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>PrintWriter(String fileName)</td>
<td>使用指定的文件名创建一个新的PrintWriter,而不需要自动执行刷新</td>
</tr>
<tr>
<td>PrintWriter(Writer out,boolean autoFlush)</td>
<td>创建一个新的PrintWriter</td>
</tr>
<tr>
<td>- out:字符输出流</td>
<td></td>
</tr>
<tr>
<td>- autoFlush:一个布尔值，如果为真，则println,printf,或format方法将刷新输出缓冲区</td>
<td></td>
</tr>
</tbody></table>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_21-59-45.jpg" alt=""></p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_22-03-30.jpg" alt=""></p>
<h2 id="案例：复制Java文件（打印流改进版）"><a href="#案例：复制Java文件（打印流改进版）" class="headerlink" title="案例：复制Java文件（打印流改进版）"></a>案例：复制Java文件（打印流改进版）</h2><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-09_22-16-11.jpg" alt=""></p>
<h2 id="三、对象序列化流"><a href="#三、对象序列化流" class="headerlink" title="三、对象序列化流"></a>三、对象序列化流</h2><p><strong>对象序列化</strong>：就是将对象保存到磁盘中，或者在网络中传输对象。</p>
<p>这种机制就是使用一个字节序列表示一个对象，该字节序列包括：对象的类型、对象的数据和对象中存储的属性等信息。字节序列写到文件之后，相当于文件中持久保存了一个对象的信息。</p>
<p>反之，该字节序列还可以从文件中读取回来，重构对象，对它进行反序列化</p>
<p>要实现序列化和反序列化就要使用对象序列化和对象反序列化流：</p>
<ul>
<li>对象序列化流：ObjectOutputStream</li>
<li>对象反序列化流：ObjectInputStream</li>
</ul>
<h3 id="对象序列化流"><a href="#对象序列化流" class="headerlink" title="对象序列化流"></a>对象序列化流</h3><ul>
<li>将Java对象的原始数据类型和图形写入OutputStream。可以使用ObjectInputStream读取（重构）对象。可以通过使用流的文件来实现对象的持久存储。如果流是网络套接字流，则可以在另一个主机上或另一个进程中重构对象</li>
</ul>
<p>构造方法：</p>
<ul>
<li>ObjectOutputStream(OutputStream out):创建一个写入指定的OutputStream的ObjectOutputStream</li>
</ul>
<p>序列化对象的方法：</p>
<ul>
<li>void writeObject(Object obj):将指定的对象写入ObjectOutputStream</li>
</ul>
<p>注意：</p>
<ul>
<li>一个对象要想被序列化，该对象所属的类必须实现<strong>Serializable</strong>接口</li>
<li>Serializable是一个<strong>标记接口</strong>，实现该接口，不需要重写任何方法</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_09-22-07.jpg" alt=""></p>
<h3 id="对象反序列化流"><a href="#对象反序列化流" class="headerlink" title="对象反序列化流"></a>对象反序列化流</h3><ul>
<li>ObjectInputStream反序列化前使用ObjectOutputStream编写的原始数据和对象</li>
</ul>
<p>构造方法：</p>
<ul>
<li>ObjectInputStream(InputStream in) : 创建从指定的InputStream读取的ObjectInputStream</li>
</ul>
<p>反序列化对象的方法：</p>
<ul>
<li>ObjectreadObject():从ObjectInputStream读取一个对象</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_11-50-01.jpg" alt=""></p>
<h3 id="serialVersionUID和transient"><a href="#serialVersionUID和transient" class="headerlink" title="serialVersionUID和transient"></a>serialVersionUID和transient</h3><h4 id="三个疑问"><a href="#三个疑问" class="headerlink" title="三个疑问"></a>三个疑问</h4><blockquote>
<ol>
<li>用对象序列化流序列化了一个对象后，加入修改了类所属的类文件，读取数据会不会出问题？</li>
</ol>
</blockquote>
<ul>
<li>会，并抛出<strong>InvalidClassException</strong>异常 </li>
<li><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_13-40-22.jpg" alt=""></li>
</ul>
<hr>
<blockquote>
<ol start="2">
<li>如何解决？</li>
</ol>
</blockquote>
<ul>
<li><p>给所属对象的类加一个<strong>serialVersionUID</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">long</span> serialVersionUID=<span class="number">42L</span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_13-48-33.jpg" alt=""></p>
</li>
</ul>
<hr>
<blockquote>
<ol start="3">
<li>如果一个对象中某个成员变量的值不想被序列化，如何实现？</li>
</ol>
</blockquote>
<ul>
<li><p>给该成员变量加<strong>transient</strong>关键字修饰，该关键字标记的成员变量不参与序列化过程</p>
</li>
<li><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_13-51-32.jpg" alt=""></p>
</li>
</ul>
<h2 id="四、Properties"><a href="#四、Properties" class="headerlink" title="四、Properties"></a>四、Properties</h2><p>Properties概述:</p>
<ul>
<li>是一个Map体系的集合类</li>
<li>Properties可以保存到流中或从流中加载</li>
</ul>
<p>Properties作为Map集合的使用</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-11_14-09-10.jpg" alt=""></p>
<h4 id="Properties作为集合的特有方法"><a href="#Properties作为集合的特有方法" class="headerlink" title="Properties作为集合的特有方法"></a>Properties作为集合的特有方法</h4><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>Object setProperty(String key,String value)</td>
<td>设置集合的键和值，都是String类型，底层调用Hashtable方法put</td>
</tr>
<tr>
<td>String getProperty（String key）</td>
<td>使用此属性列表中指定的键搜索属性</td>
</tr>
<tr>
<td>Set<String> stringPropertyNames()</td>
<td>从属性列表中返回一个不可修改的键集，其中键及其对应的值是字符串</td>
</tr>
</tbody></table>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-12_11-01-15.jpg" alt=""></p>
<h4 id="Properties和IO流结合的方法："><a href="#Properties和IO流结合的方法：" class="headerlink" title="Properties和IO流结合的方法："></a>Properties和IO流结合的方法：</h4><table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>void load(InputStream inStream)</td>
<td>从输入字节流读取属性列表（键和元素对）</td>
</tr>
<tr>
<td>void load(Reader reader)</td>
<td>从输入字符读取属性列表（键和元素对）</td>
</tr>
<tr>
<td>void store(OutputStream out,String comments)</td>
<td>将此属性列表（键和元素对）写入此Properties表中，以适合于使用load(InputStream)方法的格式写入输出字节流</td>
</tr>
<tr>
<td>void store(Writer writer,String comments)</td>
<td>将此属性列表（键和元素对）写入此Properties表中，以合适使用load(Reader)方法的格式写入输出字符流</td>
</tr>
</tbody></table>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> special;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.FileReader;</span><br><span class="line"><span class="keyword">import</span> java.io.FileWriter;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">properties_3</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line"><span class="comment">//		mystore();</span></span><br><span class="line">		myload();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">myload</span><span class="params">()</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">		Properties pro=<span class="keyword">new</span> Properties();</span><br><span class="line">		FileReader fr=<span class="keyword">new</span> FileReader(<span class="string">"properties_3.txt"</span>);</span><br><span class="line">        pro.load(fr);<span class="comment">//文件中的数据加载到集合</span></span><br><span class="line">        System.out.println(pro);</span><br><span class="line">        fr.close();</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">mystore</span><span class="params">()</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">		Properties pro=<span class="keyword">new</span> Properties();</span><br><span class="line">		pro.setProperty(<span class="string">"179200"</span>, <span class="string">"王玉"</span>);</span><br><span class="line">		pro.setProperty(<span class="string">"179222"</span>, <span class="string">"李金"</span>);</span><br><span class="line">		pro.setProperty(<span class="string">"179233"</span>, <span class="string">"赵柳"</span>);</span><br><span class="line">		FileWriter fw=<span class="keyword">new</span> FileWriter(<span class="string">"properties_3.txt"</span>);</span><br><span class="line">		pro.store(fw,<span class="keyword">null</span>);<span class="comment">//集合中的数据保存到文件</span></span><br><span class="line">		fw.close();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-12_12-53-49.jpg" alt=""></p>
<h2 id="案例：游戏次数"><a href="#案例：游戏次数" class="headerlink" title="案例：游戏次数"></a>案例：游戏次数</h2><p>需求：请写程序实现猜数字小游戏，只能试玩3次，若继续玩，提示游戏试玩已经结束，想玩请充值。</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2020-08-12_13-54-42.jpg" alt=""></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> special;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.FileReader;</span><br><span class="line"><span class="keyword">import</span> java.io.FileWriter;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.Properties;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Game_test</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> IOException</span>&#123;</span><br><span class="line">		Properties pro=<span class="keyword">new</span> Properties();</span><br><span class="line">		FileReader fr=<span class="keyword">new</span> FileReader(<span class="string">"game.txt"</span>);</span><br><span class="line">		pro.load(fr);</span><br><span class="line">		<span class="comment">//获取文件中count值</span></span><br><span class="line">		<span class="keyword">int</span> num=Integer.parseInt(pro.getProperty(<span class="string">"count"</span>));</span><br><span class="line">		fr.close();</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">if</span>(num&lt;<span class="number">3</span>)&#123;</span><br><span class="line">			Game.caishuzi();</span><br><span class="line">			num++;</span><br><span class="line">			pro.setProperty(<span class="string">"count"</span>,String.valueOf(num));</span><br><span class="line">			FileWriter fw=<span class="keyword">new</span> FileWriter(<span class="string">"game.txt"</span>);</span><br><span class="line">			pro.store(fw, <span class="keyword">null</span>);</span><br><span class="line">		&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">			System.out.println(<span class="string">"游戏试玩已经结束，请充值"</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Properties/" rel="tag">Properties</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AF%B9%E8%B1%A1%E5%BA%8F%E5%88%97%E5%8C%96%E6%B5%81/" rel="tag">对象序列化流</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%89%93%E5%8D%B0%E6%B5%81/" rel="tag">打印流</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%89%B9%E6%AE%8A%E6%93%8D%E4%BD%9C%E6%B5%81/" rel="tag">特殊操作流</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/08/14/Java%E5%A4%9A%E7%BA%BF%E7%A8%8B-%E5%AE%9E%E7%8E%B0%E5%A4%9A%E7%BA%BF%E7%A8%8B/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            Java多线程(实现多线程)
          
        </div>
      </a>
    
    
      <a href="/2020/08/09/%E4%BB%8E%E6%B5%81%E5%BC%80%E5%A7%8B%E7%9A%84IO%E4%B8%96%E7%95%8C%E7%94%9F%E6%B4%BB-%E4%B8%89/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">从流开始的IO世界生活(三)</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        notify: false,
        verify: '',
        app_id: '',
        app_key: '',
        path: window.location.pathname,
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020-2021
        张金
      </li>
      <li>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
        <img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/beian.png">
        <a href="https://beian.miit.gov.cn"  style="color:#f72b07" target="_blank">陕ICP备20002449号</a>
      </li>

    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Yolin"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/playlist">歌单</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/video">视频</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友情链接</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['肠断月明红豆蔻,','月似当时,','人似当时否？'],
    startDelay: 1500,
    typeSpeed: 200,
    loop: true,
    backSpeed: 40,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: true
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>



<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>